{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>日净值</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-09-22</td>\n",
       "      <td>3837.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-09-25</td>\n",
       "      <td>3817.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-09-26</td>\n",
       "      <td>3820.78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-09-27</td>\n",
       "      <td>3821.20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-09-28</td>\n",
       "      <td>3822.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1294</th>\n",
       "      <td>2022-09-20</td>\n",
       "      <td>3932.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1295</th>\n",
       "      <td>2022-09-20</td>\n",
       "      <td>3928.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1296</th>\n",
       "      <td>2022-09-20</td>\n",
       "      <td>3932.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1297</th>\n",
       "      <td>2022-09-20</td>\n",
       "      <td>3928.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1298</th>\n",
       "      <td>2022-09-20</td>\n",
       "      <td>3932.84</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1299 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             日期      日净值\n",
       "0    2017-09-22  3837.73\n",
       "1    2017-09-25  3817.79\n",
       "2    2017-09-26  3820.78\n",
       "3    2017-09-27  3821.20\n",
       "4    2017-09-28  3822.54\n",
       "...         ...      ...\n",
       "1294 2022-09-20  3932.84\n",
       "1295 2022-09-20  3928.00\n",
       "1296 2022-09-20  3932.84\n",
       "1297 2022-09-20  3928.00\n",
       "1298 2022-09-20  3932.84\n",
       "\n",
       "[1299 rows x 2 columns]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_excel('./分析算法(日净值）20221212.xlsx', usecols=[0, 1], skiprows=1)\n",
    "df"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 日净值算法\n",
    "1. 每日先计算过去4日盈亏  \n",
    "    `计算公式：=当日价格/4日前价格-1（Excel公式：=B6/B2-1）`\n",
    "2. 对计算出来的4日盈亏取绝对值+1和-1  \n",
    "    `计算公式：=4日盈亏值如果大于等于零，输出+1,否则输出-1（Excel公式：=IF(C6>0,1,-1))`\n",
    "3. 累加四日盈亏绝对值：累加过去9日的4日盈亏取绝对值  \n",
    "    `计算公式：=累加过去9日的4日盈亏取绝对值（Excel公式：=SUM(D6:D14)）`\n",
    "4. 9日累加绝对值：对计算出来的9日累加数字取绝对值+1和0   \n",
    "    `计算公式：=9日累加数值如果大于等于零，输出+1,否则输出0 （Excel公式：=IF(E14>0,1,0)）`\n",
    "5. 计算过去20日，9日累加绝对值中，绝对数合计占比  \n",
    "    `计算公式：=过去20日绝对数合计/20*100%（Excel公式：=SUM(F14:F33)/20）`\n",
    "6. 计算过去60日，9日累加绝对值中，绝对数合计占比  \n",
    "    `计算公式：=过去60日绝对数合计/60*100%（Excel公式：=SUM(F14:F73)/60）`\n",
    "7. 计算过去120日，9日累加绝对值中，绝对数合计占比  \n",
    "    `计算公式：=过去120日绝对数合计/120*100%（Excel公式：=SUM(F14:F133)/120）`\n",
    "8. 计算过去240日，9日累加绝对值中，绝对数合计占比  \n",
    "    `计算公式：=过去240日绝对数合计/240*100%（Excel公式：=SUM(F14:F253)/240）`\n",
    "9. 计算20日、60日、120日、240日，非等权重比率  \n",
    "    `计算公式：20日比率*40%+60日比率*30%+120日比率*20%+240日比率*10%（Excel公式：=H253*0.4+I253*0.3+J253*0.2+K253*0.1）`\n",
    "10. 计算20日、60日、120日、240日，非等权重比率大于等于55%，输出100%，否则输出0%  \n",
    "11. 如果20日、60日、120日、240日比例有一项数值为空值，输出None  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>日净值</th>\n",
       "      <th>4日盈亏</th>\n",
       "      <th>4日盈亏绝对值</th>\n",
       "      <th>累加4日盈亏绝对值</th>\n",
       "      <th>9日累加绝对值</th>\n",
       "      <th>20日比例</th>\n",
       "      <th>60日比例</th>\n",
       "      <th>120日比例</th>\n",
       "      <th>240日比例</th>\n",
       "      <th>非等权平均</th>\n",
       "      <th>输出结果</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>230</th>\n",
       "      <td>2018-08-31</td>\n",
       "      <td>3334.50</td>\n",
       "      <td>-0.021156</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.383333</td>\n",
       "      <td>0.366667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>231</th>\n",
       "      <td>2018-09-03</td>\n",
       "      <td>3321.82</td>\n",
       "      <td>-0.023043</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.50</td>\n",
       "      <td>0.400000</td>\n",
       "      <td>0.366667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>232</th>\n",
       "      <td>2018-09-04</td>\n",
       "      <td>3363.90</td>\n",
       "      <td>-0.006694</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.416667</td>\n",
       "      <td>0.366667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>233</th>\n",
       "      <td>2018-09-05</td>\n",
       "      <td>3298.14</td>\n",
       "      <td>-0.015801</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.366667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>234</th>\n",
       "      <td>2018-09-06</td>\n",
       "      <td>3262.88</td>\n",
       "      <td>-0.021478</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.358333</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>235</th>\n",
       "      <td>2018-09-07</td>\n",
       "      <td>3277.64</td>\n",
       "      <td>-0.013300</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.358333</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236</th>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>3230.07</td>\n",
       "      <td>-0.039784</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.350000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>2018-09-11</td>\n",
       "      <td>3224.21</td>\n",
       "      <td>-0.022416</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-7.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.350000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>2018-09-12</td>\n",
       "      <td>3202.02</td>\n",
       "      <td>-0.018652</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-9.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.350000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>2018-09-13</td>\n",
       "      <td>3236.57</td>\n",
       "      <td>-0.012530</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-9.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.350000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>2018-09-14</td>\n",
       "      <td>3242.09</td>\n",
       "      <td>0.003721</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-7.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.350000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>241</th>\n",
       "      <td>2018-09-17</td>\n",
       "      <td>3204.92</td>\n",
       "      <td>-0.005983</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-7.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.350000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>242</th>\n",
       "      <td>2018-09-18</td>\n",
       "      <td>3269.43</td>\n",
       "      <td>0.021052</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.350000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>243</th>\n",
       "      <td>2018-09-19</td>\n",
       "      <td>3312.48</td>\n",
       "      <td>0.023454</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.50</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.350000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>244</th>\n",
       "      <td>2018-09-20</td>\n",
       "      <td>3310.13</td>\n",
       "      <td>0.020986</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.433333</td>\n",
       "      <td>0.350000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>245</th>\n",
       "      <td>2018-09-21</td>\n",
       "      <td>3410.49</td>\n",
       "      <td>0.064142</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.450000</td>\n",
       "      <td>0.358333</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>246</th>\n",
       "      <td>2018-09-25</td>\n",
       "      <td>3379.80</td>\n",
       "      <td>0.033758</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.466667</td>\n",
       "      <td>0.366667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>247</th>\n",
       "      <td>2018-09-26</td>\n",
       "      <td>3417.24</td>\n",
       "      <td>0.031626</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.483333</td>\n",
       "      <td>0.375000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>2018-09-27</td>\n",
       "      <td>3403.59</td>\n",
       "      <td>0.028235</td>\n",
       "      <td>1.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>0.383333</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>249</th>\n",
       "      <td>2018-09-28</td>\n",
       "      <td>3438.86</td>\n",
       "      <td>0.008318</td>\n",
       "      <td>1.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.516667</td>\n",
       "      <td>0.391667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>250</th>\n",
       "      <td>2018-10-08</td>\n",
       "      <td>3290.90</td>\n",
       "      <td>-0.026303</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.533333</td>\n",
       "      <td>0.400000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>251</th>\n",
       "      <td>2018-10-09</td>\n",
       "      <td>3288.69</td>\n",
       "      <td>-0.037618</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.550000</td>\n",
       "      <td>0.400000</td>\n",
       "      <td>0.487500</td>\n",
       "      <td>0.473750</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>252</th>\n",
       "      <td>2018-10-10</td>\n",
       "      <td>3281.60</td>\n",
       "      <td>-0.035842</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.566667</td>\n",
       "      <td>0.400000</td>\n",
       "      <td>0.487500</td>\n",
       "      <td>0.478750</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>253</th>\n",
       "      <td>2018-10-11</td>\n",
       "      <td>3124.11</td>\n",
       "      <td>-0.091527</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.583333</td>\n",
       "      <td>0.400000</td>\n",
       "      <td>0.487500</td>\n",
       "      <td>0.483750</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>254</th>\n",
       "      <td>2018-10-12</td>\n",
       "      <td>3170.73</td>\n",
       "      <td>-0.036516</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.583333</td>\n",
       "      <td>0.391667</td>\n",
       "      <td>0.483333</td>\n",
       "      <td>0.481667</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>255</th>\n",
       "      <td>2018-10-15</td>\n",
       "      <td>3126.45</td>\n",
       "      <td>-0.049333</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.566667</td>\n",
       "      <td>0.391667</td>\n",
       "      <td>0.479167</td>\n",
       "      <td>0.476250</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>256</th>\n",
       "      <td>2018-10-16</td>\n",
       "      <td>3100.97</td>\n",
       "      <td>-0.055043</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.550000</td>\n",
       "      <td>0.391667</td>\n",
       "      <td>0.475000</td>\n",
       "      <td>0.470833</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>257</th>\n",
       "      <td>2018-10-17</td>\n",
       "      <td>3118.25</td>\n",
       "      <td>-0.001876</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-7.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.533333</td>\n",
       "      <td>0.391667</td>\n",
       "      <td>0.470833</td>\n",
       "      <td>0.465417</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>258</th>\n",
       "      <td>2018-10-18</td>\n",
       "      <td>3044.39</td>\n",
       "      <td>-0.039846</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-9.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.516667</td>\n",
       "      <td>0.391667</td>\n",
       "      <td>0.466667</td>\n",
       "      <td>0.460000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>259</th>\n",
       "      <td>2018-10-19</td>\n",
       "      <td>3134.95</td>\n",
       "      <td>0.002719</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-7.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>0.391667</td>\n",
       "      <td>0.462500</td>\n",
       "      <td>0.454583</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            日期      日净值      4日盈亏  4日盈亏绝对值  累加4日盈亏绝对值  9日累加绝对值  20日比例  \\\n",
       "230 2018-08-31  3334.50 -0.021156     -1.0        7.0      1.0   0.45   \n",
       "231 2018-09-03  3321.82 -0.023043     -1.0        5.0      1.0   0.50   \n",
       "232 2018-09-04  3363.90 -0.006694     -1.0        3.0      1.0   0.55   \n",
       "233 2018-09-05  3298.14 -0.015801     -1.0        1.0      1.0   0.60   \n",
       "234 2018-09-06  3262.88 -0.021478     -1.0       -1.0      0.0   0.60   \n",
       "235 2018-09-07  3277.64 -0.013300     -1.0       -3.0      0.0   0.60   \n",
       "236 2018-09-10  3230.07 -0.039784     -1.0       -5.0      0.0   0.60   \n",
       "237 2018-09-11  3224.21 -0.022416     -1.0       -7.0      0.0   0.60   \n",
       "238 2018-09-12  3202.02 -0.018652     -1.0       -9.0      0.0   0.60   \n",
       "239 2018-09-13  3236.57 -0.012530     -1.0       -9.0      0.0   0.60   \n",
       "240 2018-09-14  3242.09  0.003721      1.0       -7.0      0.0   0.60   \n",
       "241 2018-09-17  3204.92 -0.005983     -1.0       -7.0      0.0   0.60   \n",
       "242 2018-09-18  3269.43  0.021052      1.0       -5.0      0.0   0.55   \n",
       "243 2018-09-19  3312.48  0.023454      1.0       -3.0      0.0   0.50   \n",
       "244 2018-09-20  3310.13  0.020986      1.0       -1.0      0.0   0.45   \n",
       "245 2018-09-21  3410.49  0.064142      1.0        1.0      1.0   0.45   \n",
       "246 2018-09-25  3379.80  0.033758      1.0        3.0      1.0   0.45   \n",
       "247 2018-09-26  3417.24  0.031626      1.0        5.0      1.0   0.45   \n",
       "248 2018-09-27  3403.59  0.028235      1.0        7.0      1.0   0.45   \n",
       "249 2018-09-28  3438.86  0.008318      1.0        7.0      1.0   0.45   \n",
       "250 2018-10-08  3290.90 -0.026303     -1.0        7.0      1.0   0.45   \n",
       "251 2018-10-09  3288.69 -0.037618     -1.0        5.0      1.0   0.45   \n",
       "252 2018-10-10  3281.60 -0.035842     -1.0        3.0      1.0   0.45   \n",
       "253 2018-10-11  3124.11 -0.091527     -1.0        1.0      1.0   0.45   \n",
       "254 2018-10-12  3170.73 -0.036516     -1.0       -1.0      0.0   0.45   \n",
       "255 2018-10-15  3126.45 -0.049333     -1.0       -3.0      0.0   0.45   \n",
       "256 2018-10-16  3100.97 -0.055043     -1.0       -5.0      0.0   0.45   \n",
       "257 2018-10-17  3118.25 -0.001876     -1.0       -7.0      0.0   0.45   \n",
       "258 2018-10-18  3044.39 -0.039846     -1.0       -9.0      0.0   0.45   \n",
       "259 2018-10-19  3134.95  0.002719      1.0       -7.0      0.0   0.45   \n",
       "\n",
       "        60日比例    120日比例    240日比例     非等权平均  输出结果  \n",
       "230  0.383333  0.366667       NaN       NaN   NaN  \n",
       "231  0.400000  0.366667       NaN       NaN   NaN  \n",
       "232  0.416667  0.366667       NaN       NaN   NaN  \n",
       "233  0.433333  0.366667       NaN       NaN   NaN  \n",
       "234  0.433333  0.358333       NaN       NaN   NaN  \n",
       "235  0.433333  0.358333       NaN       NaN   NaN  \n",
       "236  0.433333  0.350000       NaN       NaN   NaN  \n",
       "237  0.433333  0.350000       NaN       NaN   NaN  \n",
       "238  0.433333  0.350000       NaN       NaN   NaN  \n",
       "239  0.433333  0.350000       NaN       NaN   NaN  \n",
       "240  0.433333  0.350000       NaN       NaN   NaN  \n",
       "241  0.433333  0.350000       NaN       NaN   NaN  \n",
       "242  0.433333  0.350000       NaN       NaN   NaN  \n",
       "243  0.433333  0.350000       NaN       NaN   NaN  \n",
       "244  0.433333  0.350000       NaN       NaN   NaN  \n",
       "245  0.450000  0.358333       NaN       NaN   NaN  \n",
       "246  0.466667  0.366667       NaN       NaN   NaN  \n",
       "247  0.483333  0.375000       NaN       NaN   NaN  \n",
       "248  0.500000  0.383333       NaN       NaN   NaN  \n",
       "249  0.516667  0.391667       NaN       NaN   NaN  \n",
       "250  0.533333  0.400000       NaN       NaN   NaN  \n",
       "251  0.550000  0.400000  0.487500  0.473750   0.0  \n",
       "252  0.566667  0.400000  0.487500  0.478750   0.0  \n",
       "253  0.583333  0.400000  0.487500  0.483750   0.0  \n",
       "254  0.583333  0.391667  0.483333  0.481667   0.0  \n",
       "255  0.566667  0.391667  0.479167  0.476250   0.0  \n",
       "256  0.550000  0.391667  0.475000  0.470833   0.0  \n",
       "257  0.533333  0.391667  0.470833  0.465417   0.0  \n",
       "258  0.516667  0.391667  0.466667  0.460000   0.0  \n",
       "259  0.500000  0.391667  0.462500  0.454583   0.0  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df['4日盈亏'] = df['日净值'].rolling(5).apply(lambda series: series.iloc[4] / series.iloc[0] - 1)\n",
    "df['4日盈亏绝对值'] = df['4日盈亏'].apply(lambda val: 1 if val > 0 else -1 if not np.isnan(val) else np.nan)\n",
    "df['累加4日盈亏绝对值'] = df['4日盈亏绝对值'].rolling(9).sum()\n",
    "df['9日累加绝对值'] = df['累加4日盈亏绝对值'].apply(lambda val: 1 if val > 0 else 0 if not np.isnan(val) else np.nan)\n",
    "df['20日比例'] = df['9日累加绝对值'].rolling(20).apply(lambda series: series.sum() / 20)\n",
    "df['60日比例'] = df['9日累加绝对值'].rolling(60).apply(lambda series: series.sum() / 60)\n",
    "df['120日比例'] = df['9日累加绝对值'].rolling(120).apply(lambda series: series.sum() / 120)\n",
    "df['240日比例'] = df['9日累加绝对值'].rolling(240).apply(lambda series: series.sum() / 240)\n",
    "df['非等权平均'] = df.apply(lambda row: row['20日比例']*0.4 + row['60日比例']*0.3 + row['120日比例']*0.2 + row['240日比例']*0.1, axis=1)\n",
    "df['输出结果'] = df['非等权平均'].apply(lambda val: 1 if val >= 0.55 else 0 if not np.isnan(val) else np.nan)\n",
    "display(df.iloc[230:260, :])\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 周净值算法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as pn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>周净值</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2005-04-08</td>\n",
       "      <td>1003.445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2005-04-15</td>\n",
       "      <td>974.082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2005-04-22</td>\n",
       "      <td>939.101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2005-04-29</td>\n",
       "      <td>932.395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2005-05-13</td>\n",
       "      <td>887.543</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>885</th>\n",
       "      <td>2022-08-19</td>\n",
       "      <td>3932.680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>886</th>\n",
       "      <td>2022-08-26</td>\n",
       "      <td>3932.680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>887</th>\n",
       "      <td>2022-09-02</td>\n",
       "      <td>3932.680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>888</th>\n",
       "      <td>2022-09-09</td>\n",
       "      <td>3932.680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>889</th>\n",
       "      <td>2022-09-16</td>\n",
       "      <td>3932.680</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>890 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            日期       周净值\n",
       "0   2005-04-08  1003.445\n",
       "1   2005-04-15   974.082\n",
       "2   2005-04-22   939.101\n",
       "3   2005-04-29   932.395\n",
       "4   2005-05-13   887.543\n",
       "..         ...       ...\n",
       "885 2022-08-19  3932.680\n",
       "886 2022-08-26  3932.680\n",
       "887 2022-09-02  3932.680\n",
       "888 2022-09-09  3932.680\n",
       "889 2022-09-16  3932.680\n",
       "\n",
       "[890 rows x 2 columns]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_excel('./分析算法(周净值)20221212.xlsx', usecols=[0, 1], skiprows=1)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>周净值</th>\n",
       "      <th>周盈亏</th>\n",
       "      <th>周盈亏绝对值</th>\n",
       "      <th>累加7周盈亏绝对值</th>\n",
       "      <th>7周累加绝对值</th>\n",
       "      <th>20日比例</th>\n",
       "      <th>60日比例</th>\n",
       "      <th>120日比例</th>\n",
       "      <th>240日比例</th>\n",
       "      <th>非等权平均</th>\n",
       "      <th>8周收益正负</th>\n",
       "      <th>8周收益正负绝对</th>\n",
       "      <th>非等权平均+8周</th>\n",
       "      <th>输出结果</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>2006-04-14</td>\n",
       "      <td>1118.607</td>\n",
       "      <td>15.453</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.750000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>98.239</td>\n",
       "      <td>0.15</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>2006-04-21</td>\n",
       "      <td>1149.158</td>\n",
       "      <td>30.551</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.791667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>99.714</td>\n",
       "      <td>0.15</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>2006-04-28</td>\n",
       "      <td>1172.347</td>\n",
       "      <td>23.189</td>\n",
       "      <td>1.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.833333</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>130.670</td>\n",
       "      <td>0.15</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>2006-05-12</td>\n",
       "      <td>1296.257</td>\n",
       "      <td>123.910</td>\n",
       "      <td>1.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.875000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>287.360</td>\n",
       "      <td>0.15</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>2006-05-19</td>\n",
       "      <td>1366.097</td>\n",
       "      <td>69.840</td>\n",
       "      <td>1.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.916667</td>\n",
       "      <td>0.729167</td>\n",
       "      <td>0.956250</td>\n",
       "      <td>342.082</td>\n",
       "      <td>0.15</td>\n",
       "      <td>1.106250</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>2006-05-26</td>\n",
       "      <td>1331.020</td>\n",
       "      <td>-35.077</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.958333</td>\n",
       "      <td>0.750000</td>\n",
       "      <td>0.966667</td>\n",
       "      <td>288.419</td>\n",
       "      <td>0.15</td>\n",
       "      <td>1.116667</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>2006-06-02</td>\n",
       "      <td>1390.116</td>\n",
       "      <td>59.096</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.770833</td>\n",
       "      <td>0.977083</td>\n",
       "      <td>329.028</td>\n",
       "      <td>0.15</td>\n",
       "      <td>1.127083</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>2006-06-09</td>\n",
       "      <td>1294.185</td>\n",
       "      <td>-95.931</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.791667</td>\n",
       "      <td>0.979167</td>\n",
       "      <td>191.031</td>\n",
       "      <td>0.15</td>\n",
       "      <td>1.129167</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>2006-06-16</td>\n",
       "      <td>1318.010</td>\n",
       "      <td>23.825</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.812500</td>\n",
       "      <td>0.981250</td>\n",
       "      <td>199.403</td>\n",
       "      <td>0.15</td>\n",
       "      <td>1.131250</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>2006-06-23</td>\n",
       "      <td>1339.446</td>\n",
       "      <td>21.436</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.833333</td>\n",
       "      <td>0.983333</td>\n",
       "      <td>190.288</td>\n",
       "      <td>0.15</td>\n",
       "      <td>1.133333</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>2006-06-30</td>\n",
       "      <td>1393.963</td>\n",
       "      <td>54.517</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.854167</td>\n",
       "      <td>0.985417</td>\n",
       "      <td>221.616</td>\n",
       "      <td>0.15</td>\n",
       "      <td>1.135417</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>2006-07-07</td>\n",
       "      <td>1410.429</td>\n",
       "      <td>16.466</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.875000</td>\n",
       "      <td>0.987500</td>\n",
       "      <td>114.172</td>\n",
       "      <td>0.15</td>\n",
       "      <td>1.137500</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>2006-07-14</td>\n",
       "      <td>1357.129</td>\n",
       "      <td>-53.300</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.875000</td>\n",
       "      <td>0.987500</td>\n",
       "      <td>-8.968</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.837500</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>2006-07-21</td>\n",
       "      <td>1356.033</td>\n",
       "      <td>-1.096</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.875000</td>\n",
       "      <td>0.987500</td>\n",
       "      <td>25.013</td>\n",
       "      <td>0.15</td>\n",
       "      <td>1.137500</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>2006-07-28</td>\n",
       "      <td>1341.393</td>\n",
       "      <td>-14.640</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.875000</td>\n",
       "      <td>0.987500</td>\n",
       "      <td>-48.723</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.837500</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>2006-08-04</td>\n",
       "      <td>1241.908</td>\n",
       "      <td>-99.485</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.75</td>\n",
       "      <td>0.916667</td>\n",
       "      <td>0.958333</td>\n",
       "      <td>0.854167</td>\n",
       "      <td>0.852083</td>\n",
       "      <td>-52.277</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.702083</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>2006-08-11</td>\n",
       "      <td>1275.654</td>\n",
       "      <td>33.746</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.50</td>\n",
       "      <td>0.833333</td>\n",
       "      <td>0.916667</td>\n",
       "      <td>0.833333</td>\n",
       "      <td>0.716667</td>\n",
       "      <td>-42.356</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.566667</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>2006-08-18</td>\n",
       "      <td>1267.866</td>\n",
       "      <td>-7.788</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.750000</td>\n",
       "      <td>0.875000</td>\n",
       "      <td>0.812500</td>\n",
       "      <td>0.581250</td>\n",
       "      <td>-71.580</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.431250</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>2006-08-25</td>\n",
       "      <td>1295.437</td>\n",
       "      <td>27.571</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.666667</td>\n",
       "      <td>0.833333</td>\n",
       "      <td>0.791667</td>\n",
       "      <td>0.445833</td>\n",
       "      <td>-98.526</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.295833</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>2006-09-01</td>\n",
       "      <td>1318.099</td>\n",
       "      <td>22.662</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.583333</td>\n",
       "      <td>0.791667</td>\n",
       "      <td>0.770833</td>\n",
       "      <td>0.410417</td>\n",
       "      <td>-92.330</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.260417</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           日期       周净值      周盈亏  周盈亏绝对值  累加7周盈亏绝对值  7周累加绝对值  20日比例     60日比例  \\\n",
       "50 2006-04-14  1118.607   15.453     1.0        3.0      1.0   1.00  1.000000   \n",
       "51 2006-04-21  1149.158   30.551     1.0        5.0      1.0   1.00  1.000000   \n",
       "52 2006-04-28  1172.347   23.189     1.0        7.0      1.0   1.00  1.000000   \n",
       "53 2006-05-12  1296.257  123.910     1.0        7.0      1.0   1.00  1.000000   \n",
       "54 2006-05-19  1366.097   69.840     1.0        7.0      1.0   1.00  1.000000   \n",
       "55 2006-05-26  1331.020  -35.077    -1.0        5.0      1.0   1.00  1.000000   \n",
       "56 2006-06-02  1390.116   59.096     1.0        5.0      1.0   1.00  1.000000   \n",
       "57 2006-06-09  1294.185  -95.931    -1.0        3.0      1.0   1.00  1.000000   \n",
       "58 2006-06-16  1318.010   23.825     1.0        3.0      1.0   1.00  1.000000   \n",
       "59 2006-06-23  1339.446   21.436     1.0        3.0      1.0   1.00  1.000000   \n",
       "60 2006-06-30  1393.963   54.517     1.0        3.0      1.0   1.00  1.000000   \n",
       "61 2006-07-07  1410.429   16.466     1.0        3.0      1.0   1.00  1.000000   \n",
       "62 2006-07-14  1357.129  -53.300    -1.0        3.0      1.0   1.00  1.000000   \n",
       "63 2006-07-21  1356.033   -1.096    -1.0        1.0      1.0   1.00  1.000000   \n",
       "64 2006-07-28  1341.393  -14.640    -1.0        1.0      1.0   1.00  1.000000   \n",
       "65 2006-08-04  1241.908  -99.485    -1.0       -1.0      0.0   0.75  0.916667   \n",
       "66 2006-08-11  1275.654   33.746     1.0       -1.0      0.0   0.50  0.833333   \n",
       "67 2006-08-18  1267.866   -7.788    -1.0       -3.0      0.0   0.25  0.750000   \n",
       "68 2006-08-25  1295.437   27.571     1.0       -3.0      0.0   0.00  0.666667   \n",
       "69 2006-09-01  1318.099   22.662     1.0       -1.0      0.0   0.00  0.583333   \n",
       "\n",
       "      120日比例    240日比例     非等权平均   8周收益正负  8周收益正负绝对  非等权平均+8周  输出结果  \n",
       "50  0.750000       NaN       NaN   98.239      0.15       NaN   NaN  \n",
       "51  0.791667       NaN       NaN   99.714      0.15       NaN   NaN  \n",
       "52  0.833333       NaN       NaN  130.670      0.15       NaN   NaN  \n",
       "53  0.875000       NaN       NaN  287.360      0.15       NaN   NaN  \n",
       "54  0.916667  0.729167  0.956250  342.082      0.15  1.106250   1.0  \n",
       "55  0.958333  0.750000  0.966667  288.419      0.15  1.116667   1.0  \n",
       "56  1.000000  0.770833  0.977083  329.028      0.15  1.127083   1.0  \n",
       "57  1.000000  0.791667  0.979167  191.031      0.15  1.129167   1.0  \n",
       "58  1.000000  0.812500  0.981250  199.403      0.15  1.131250   1.0  \n",
       "59  1.000000  0.833333  0.983333  190.288      0.15  1.133333   1.0  \n",
       "60  1.000000  0.854167  0.985417  221.616      0.15  1.135417   1.0  \n",
       "61  1.000000  0.875000  0.987500  114.172      0.15  1.137500   1.0  \n",
       "62  1.000000  0.875000  0.987500   -8.968     -0.15  0.837500   1.0  \n",
       "63  1.000000  0.875000  0.987500   25.013      0.15  1.137500   1.0  \n",
       "64  1.000000  0.875000  0.987500  -48.723     -0.15  0.837500   1.0  \n",
       "65  0.958333  0.854167  0.852083  -52.277     -0.15  0.702083   1.0  \n",
       "66  0.916667  0.833333  0.716667  -42.356     -0.15  0.566667   1.0  \n",
       "67  0.875000  0.812500  0.581250  -71.580     -0.15  0.431250   0.0  \n",
       "68  0.833333  0.791667  0.445833  -98.526     -0.15  0.295833   0.0  \n",
       "69  0.791667  0.770833  0.410417  -92.330     -0.15  0.260417   0.0  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>周净值</th>\n",
       "      <th>周盈亏</th>\n",
       "      <th>周盈亏绝对值</th>\n",
       "      <th>累加7周盈亏绝对值</th>\n",
       "      <th>7周累加绝对值</th>\n",
       "      <th>20日比例</th>\n",
       "      <th>60日比例</th>\n",
       "      <th>120日比例</th>\n",
       "      <th>240日比例</th>\n",
       "      <th>非等权平均</th>\n",
       "      <th>8周收益正负</th>\n",
       "      <th>8周收益正负绝对</th>\n",
       "      <th>非等权平均+8周</th>\n",
       "      <th>输出结果</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>870</th>\n",
       "      <td>2022-05-06</td>\n",
       "      <td>3908.82</td>\n",
       "      <td>-107.42</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.083333</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.458333</td>\n",
       "      <td>0.137500</td>\n",
       "      <td>-397.70</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>-0.012500</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>871</th>\n",
       "      <td>2022-05-13</td>\n",
       "      <td>3988.60</td>\n",
       "      <td>79.78</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.291667</td>\n",
       "      <td>0.437500</td>\n",
       "      <td>0.102083</td>\n",
       "      <td>-277.30</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>-0.047917</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>872</th>\n",
       "      <td>2022-05-20</td>\n",
       "      <td>4077.60</td>\n",
       "      <td>89.00</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.250000</td>\n",
       "      <td>0.437500</td>\n",
       "      <td>0.093750</td>\n",
       "      <td>-96.97</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>-0.056250</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>873</th>\n",
       "      <td>2022-05-27</td>\n",
       "      <td>4001.30</td>\n",
       "      <td>-76.30</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.208333</td>\n",
       "      <td>0.437500</td>\n",
       "      <td>0.085417</td>\n",
       "      <td>-274.86</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>-0.064583</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>874</th>\n",
       "      <td>2022-06-02</td>\n",
       "      <td>4089.57</td>\n",
       "      <td>88.27</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.083333</td>\n",
       "      <td>0.208333</td>\n",
       "      <td>0.437500</td>\n",
       "      <td>0.210417</td>\n",
       "      <td>-141.20</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.060417</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>875</th>\n",
       "      <td>2022-06-10</td>\n",
       "      <td>4238.99</td>\n",
       "      <td>149.42</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.50</td>\n",
       "      <td>0.166667</td>\n",
       "      <td>0.208333</td>\n",
       "      <td>0.458333</td>\n",
       "      <td>0.337500</td>\n",
       "      <td>50.24</td>\n",
       "      <td>0.15</td>\n",
       "      <td>0.487500</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>876</th>\n",
       "      <td>2022-06-17</td>\n",
       "      <td>4309.04</td>\n",
       "      <td>70.05</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.75</td>\n",
       "      <td>0.250000</td>\n",
       "      <td>0.208333</td>\n",
       "      <td>0.479167</td>\n",
       "      <td>0.464583</td>\n",
       "      <td>295.79</td>\n",
       "      <td>0.15</td>\n",
       "      <td>0.614583</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>877</th>\n",
       "      <td>2022-06-24</td>\n",
       "      <td>4394.77</td>\n",
       "      <td>85.73</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.208333</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>0.591667</td>\n",
       "      <td>378.53</td>\n",
       "      <td>0.15</td>\n",
       "      <td>0.741667</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>878</th>\n",
       "      <td>2022-07-01</td>\n",
       "      <td>4466.72</td>\n",
       "      <td>71.95</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.416667</td>\n",
       "      <td>0.250000</td>\n",
       "      <td>0.520833</td>\n",
       "      <td>0.627083</td>\n",
       "      <td>557.90</td>\n",
       "      <td>0.15</td>\n",
       "      <td>0.777083</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>879</th>\n",
       "      <td>2022-07-08</td>\n",
       "      <td>4428.78</td>\n",
       "      <td>-37.94</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>0.291667</td>\n",
       "      <td>0.541667</td>\n",
       "      <td>0.662500</td>\n",
       "      <td>440.18</td>\n",
       "      <td>0.15</td>\n",
       "      <td>0.812500</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>880</th>\n",
       "      <td>2022-07-15</td>\n",
       "      <td>4284.53</td>\n",
       "      <td>-144.25</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.583333</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.562500</td>\n",
       "      <td>0.697917</td>\n",
       "      <td>206.93</td>\n",
       "      <td>0.15</td>\n",
       "      <td>0.847917</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>881</th>\n",
       "      <td>2022-07-22</td>\n",
       "      <td>4238.23</td>\n",
       "      <td>-46.30</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.666667</td>\n",
       "      <td>0.375000</td>\n",
       "      <td>0.583333</td>\n",
       "      <td>0.733333</td>\n",
       "      <td>236.93</td>\n",
       "      <td>0.15</td>\n",
       "      <td>0.883333</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>882</th>\n",
       "      <td>2022-07-29</td>\n",
       "      <td>4170.10</td>\n",
       "      <td>-68.13</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.75</td>\n",
       "      <td>0.666667</td>\n",
       "      <td>0.375000</td>\n",
       "      <td>0.583333</td>\n",
       "      <td>0.633333</td>\n",
       "      <td>80.53</td>\n",
       "      <td>0.15</td>\n",
       "      <td>0.783333</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>883</th>\n",
       "      <td>2022-08-05</td>\n",
       "      <td>4156.91</td>\n",
       "      <td>-13.19</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.50</td>\n",
       "      <td>0.666667</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.562500</td>\n",
       "      <td>0.522917</td>\n",
       "      <td>-82.08</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.372917</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>884</th>\n",
       "      <td>2022-08-12</td>\n",
       "      <td>3932.68</td>\n",
       "      <td>-224.23</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.666667</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.541667</td>\n",
       "      <td>0.420833</td>\n",
       "      <td>-376.36</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.270833</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>885</th>\n",
       "      <td>2022-08-19</td>\n",
       "      <td>3932.68</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-7.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.666667</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.520833</td>\n",
       "      <td>0.318750</td>\n",
       "      <td>-462.09</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.168750</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>886</th>\n",
       "      <td>2022-08-26</td>\n",
       "      <td>3932.68</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-7.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.583333</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>0.291667</td>\n",
       "      <td>-534.04</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.141667</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>887</th>\n",
       "      <td>2022-09-02</td>\n",
       "      <td>3932.68</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-7.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.479167</td>\n",
       "      <td>0.264583</td>\n",
       "      <td>-496.10</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.114583</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>888</th>\n",
       "      <td>2022-09-09</td>\n",
       "      <td>3932.68</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-7.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.416667</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.458333</td>\n",
       "      <td>0.237500</td>\n",
       "      <td>-351.85</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.087500</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>889</th>\n",
       "      <td>2022-09-16</td>\n",
       "      <td>3932.68</td>\n",
       "      <td>0.00</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-7.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>0.437500</td>\n",
       "      <td>0.210417</td>\n",
       "      <td>-305.55</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>0.060417</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            日期      周净值     周盈亏  周盈亏绝对值  累加7周盈亏绝对值  7周累加绝对值  20日比例     60日比例  \\\n",
       "870 2022-05-06  3908.82 -107.42    -1.0       -3.0      0.0   0.00  0.083333   \n",
       "871 2022-05-13  3988.60   79.78     1.0       -1.0      0.0   0.00  0.000000   \n",
       "872 2022-05-20  4077.60   89.00     1.0       -1.0      0.0   0.00  0.000000   \n",
       "873 2022-05-27  4001.30  -76.30    -1.0       -1.0      0.0   0.00  0.000000   \n",
       "874 2022-06-02  4089.57   88.27     1.0        1.0      1.0   0.25  0.083333   \n",
       "875 2022-06-10  4238.99  149.42     1.0        3.0      1.0   0.50  0.166667   \n",
       "876 2022-06-17  4309.04   70.05     1.0        3.0      1.0   0.75  0.250000   \n",
       "877 2022-06-24  4394.77   85.73     1.0        5.0      1.0   1.00  0.333333   \n",
       "878 2022-07-01  4466.72   71.95     1.0        5.0      1.0   1.00  0.416667   \n",
       "879 2022-07-08  4428.78  -37.94    -1.0        3.0      1.0   1.00  0.500000   \n",
       "880 2022-07-15  4284.53 -144.25    -1.0        3.0      1.0   1.00  0.583333   \n",
       "881 2022-07-22  4238.23  -46.30    -1.0        1.0      1.0   1.00  0.666667   \n",
       "882 2022-07-29  4170.10  -68.13    -1.0       -1.0      0.0   0.75  0.666667   \n",
       "883 2022-08-05  4156.91  -13.19    -1.0       -3.0      0.0   0.50  0.666667   \n",
       "884 2022-08-12  3932.68 -224.23    -1.0       -5.0      0.0   0.25  0.666667   \n",
       "885 2022-08-19  3932.68    0.00    -1.0       -7.0      0.0   0.00  0.666667   \n",
       "886 2022-08-26  3932.68    0.00    -1.0       -7.0      0.0   0.00  0.583333   \n",
       "887 2022-09-02  3932.68    0.00    -1.0       -7.0      0.0   0.00  0.500000   \n",
       "888 2022-09-09  3932.68    0.00    -1.0       -7.0      0.0   0.00  0.416667   \n",
       "889 2022-09-16  3932.68    0.00    -1.0       -7.0      0.0   0.00  0.333333   \n",
       "\n",
       "       120日比例    240日比例     非等权平均  8周收益正负  8周收益正负绝对  非等权平均+8周  输出结果  \n",
       "870  0.333333  0.458333  0.137500 -397.70     -0.15 -0.012500   0.0  \n",
       "871  0.291667  0.437500  0.102083 -277.30     -0.15 -0.047917   0.0  \n",
       "872  0.250000  0.437500  0.093750  -96.97     -0.15 -0.056250   0.0  \n",
       "873  0.208333  0.437500  0.085417 -274.86     -0.15 -0.064583   0.0  \n",
       "874  0.208333  0.437500  0.210417 -141.20     -0.15  0.060417   0.0  \n",
       "875  0.208333  0.458333  0.337500   50.24      0.15  0.487500   0.0  \n",
       "876  0.208333  0.479167  0.464583  295.79      0.15  0.614583   1.0  \n",
       "877  0.208333  0.500000  0.591667  378.53      0.15  0.741667   1.0  \n",
       "878  0.250000  0.520833  0.627083  557.90      0.15  0.777083   1.0  \n",
       "879  0.291667  0.541667  0.662500  440.18      0.15  0.812500   1.0  \n",
       "880  0.333333  0.562500  0.697917  206.93      0.15  0.847917   1.0  \n",
       "881  0.375000  0.583333  0.733333  236.93      0.15  0.883333   1.0  \n",
       "882  0.375000  0.583333  0.633333   80.53      0.15  0.783333   1.0  \n",
       "883  0.333333  0.562500  0.522917  -82.08     -0.15  0.372917   0.0  \n",
       "884  0.333333  0.541667  0.420833 -376.36     -0.15  0.270833   0.0  \n",
       "885  0.333333  0.520833  0.318750 -462.09     -0.15  0.168750   0.0  \n",
       "886  0.333333  0.500000  0.291667 -534.04     -0.15  0.141667   0.0  \n",
       "887  0.333333  0.479167  0.264583 -496.10     -0.15  0.114583   0.0  \n",
       "888  0.333333  0.458333  0.237500 -351.85     -0.15  0.087500   0.0  \n",
       "889  0.333333  0.437500  0.210417 -305.55     -0.15  0.060417   0.0  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df['周盈亏'] = df['周净值'].rolling(2).apply(lambda series: series.iloc[1] - series.iloc[0])\n",
    "df['周盈亏绝对值'] = df['周盈亏'].apply(lambda val: 1 if val > 0 else -1 if not np.isnan(val) else np.nan)\n",
    "df['累加7周盈亏绝对值'] = df['周盈亏绝对值'].rolling(7).sum()\n",
    "df['7周累加绝对值'] = df['累加7周盈亏绝对值'].apply(lambda val: 1 if val > 0 else 0 if not np.isnan(val) else np.nan)\n",
    "df['20日比例'] = df['7周累加绝对值'].rolling(4).apply(lambda series: series.sum() / 4)\n",
    "df['60日比例'] = df['7周累加绝对值'].rolling(12).apply(lambda series: series.sum() / 12)\n",
    "df['120日比例'] = df['7周累加绝对值'].rolling(24).apply(lambda series: series.sum() / 24)\n",
    "df['240日比例'] = df['7周累加绝对值'].rolling(48).apply(lambda series: series.sum() / 48)\n",
    "df['非等权平均'] = df.apply(lambda row: row['20日比例']*0.4 + row['60日比例']*0.3 + row['120日比例']*0.2 + row['240日比例']*0.1, axis=1)\n",
    "df['8周收益正负'] = df['周净值'].rolling(9).apply(lambda series: series.iloc[-1] - series.iloc[0])\n",
    "df['8周收益正负绝对'] = df['8周收益正负'].apply(lambda val: 0.15 if val >= 0 else -0.15 if not np.isnan(val) else np.nan)\n",
    "df['非等权平均+8周'] = df.apply(lambda row: row['非等权平均'] + row['8周收益正负绝对'], axis=1)\n",
    "df['输出结果'] = df['非等权平均+8周'].apply(lambda val: 1 if val >= 0.55 else 0 if not np.isnan(val) else np.nan)\n",
    "display(df.iloc[50:70, :])\n",
    "display(df.tail(20))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "da",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.15 (default, Nov 24 2022, 15:19:38) \n[GCC 11.2.0]"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "5bbe6be4515f327d9816fa77c55ed47ebbddd9fecf74d53dcda938f7510c6335"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
